package com.pk.platform.business.apply.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.pk.platform.business.apply.dao.IVacationDao;
import com.pk.platform.business.apply.service.IVacationService;
import com.pk.platform.business.apply.vo.VacationVO;
import com.pk.platform.business.flow.service.IFlowExecuteService;
import com.pk.platform.domain.apply.Vacation;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.constant.Constant;
import com.pk.platform.util.page.Pager;

public class VacationServiceImpl implements IVacationService {

	private IVacationDao vacationDao;
	
	private IFlowExecuteService flowExecuteService;
	
	public void saveVacation(Vacation vacation)
	{
		if(StringConverter.isNotNull(vacation.getId()))
		{
			Vacation va = this.queryVacationById(vacation.getId());
			va.setEmployee(vacation.getEmployee());
			va.setFromTime(vacation.getFromTime());
			va.setToTime(vacation.getToTime());
			va.setDays(vacation.getDays());
			va.setHours(vacation.getHours());
			va.setRemark(vacation.getRemark());
			va.setLastModifyTime(new Date());
		}
		else
		{
			vacationDao.add(vacation);
			flowExecuteService.startFlow(vacation);
		}
	}
	
	public Vacation queryVacationById(String id)
	{
		return vacationDao.get(Vacation.class, id);
	}
	
	public void delVacation(String id)
	{
		Vacation vac = this.queryVacationById(id);
		if(Constant.DRAFT.equals(vac.getStatus()))
		{
			vacationDao.delete(Vacation.class, id);
			flowExecuteService.delRelativeHistory(Vacation.class.getName(), id);
		}
	}
	
	public List<Map<String, Object>> queryTaskVacationList(VacationVO vvo, Pager pager)
	{
		return vacationDao.queryTaskVacationList(vvo, pager);
	}
	
	public IVacationDao getVacationDao() {
		return vacationDao;
	}

	public void setVacationDao(IVacationDao vacationDao) {
		this.vacationDao = vacationDao;
	}

	public IFlowExecuteService getFlowExecuteService() {
		return flowExecuteService;
	}

	public void setFlowExecuteService(IFlowExecuteService flowExecuteService) {
		this.flowExecuteService = flowExecuteService;
	}

}
